ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'impact.font',
    'game.entities.player',
    'game.entities.cursor',
    'game.entities.target',
    'game.entities.follower',
    'game.entities.roundfollower',
    'game.entities.roundbullit',
    'game.entities.shooter',
    'game.levels.test',
    'game.utils',
    'game.movement'
    
).defines(function(){

MyGame = ig.Game.extend({
	gravity: 0,
	
	player: null,
	
	// Load a font
	font: new ig.Font( 'media/04b03.font.png' ),
	
    spawnTimer: null,
	
	init: function() {
        ig.input.initMouse();
        ig.input.bind(ig.KEY.MOUSE1,'shoot');
        
	this.loadLevel(LevelTest);


	this.player = this.spawnEntity(EntityPlayer,10,10);
        
    var cursor = this.spawnEntity(EntityCursor,10,10);
    
    var target = this.spawnEntity(EntityTarget,10,10,{cursor: cursor, player: this.player});
    
    this.player.target = target;
    
    this.spawnTimer = new ig.Timer();	
    
	},
	
	update: function() {        
        
        
        if( this.spawnTimer.delta() > 3 ){            
            this.spawnTimer.set( 0 );
            this.spawnEntity( EntityShooter, Math.random() * 150, Math.random() * 150, {
                player: this.player
            });
            this.spawnEntity( EntityRoundFollower, Math.random() * 150, Math.random() * 150, {
                player: this.player
            });
        }
        
		// Update all entities and backgroundMaps
		this.parent();
	},	
	draw: function() {
		// Draw all entities and backgroundMaps
		this.parent();
		
		
	
		this.font.draw( 'Entities count: ' + ig.game.entities.length, 10, 10, ig.Font.ALIGN.CENTER );
		
	},
        showInfo: function(){
            this.font.draw( 'Entities count: ' + ig.game.entities.length, 10, 10, ig.Font.ALIGN.CENTER );
        }
});


// Start the Game with 60fps, a resolution of 320x240, scaled
// up by a factor of 2
ig.main( '#canvas', MyGame, 60, 320, 240, 2 );

});
